/*
 * SDLWrapper.h
 *
 * Author: Samuel Queiroz
 */

#ifndef SDLWRAPPER_H_
#define SDLWRAPPER_H_

#include "../Thread/Threadable.h"

#include "SDL/SDL.h"

#include <vector>
using std::vector;

class SDLWrapper
	: public Threadable
{

private:

	static int const LEFT_XAXIS = 0;
	static int const LEFT_YAXIS = 1;
	static int const RIGHT_XAXIS = 3;
	static int const RIGHT_YAXIS = 4;

    SDL_Event event;
    SDL_Joystick *joystick;

	int leftXAxis;
	int leftYAxis;
	int rightXAxis;
	int rightYAxis;

	vector<Runnable *> listenerObjects;

	void init();

	void quit();

	void run();

	void notifyListeners()
	{
	   vector<Runnable *>::reverse_iterator ri;
	   for(ri = listenerObjects.rbegin(); ri != listenerObjects.rend(); ++ri)
	   {
		   (*ri)->run();
	   }
	}

public:

	void addListenerObject(Runnable *listenerObj)
	{
		listenerObjects.push_back(listenerObj);
	}

	SDL_Event *getEvent()
	{
		return &event;
	}

	SDL_Joystick *getJoystick()
	{
		return joystick;
	}

	int *getLeftXAxis()
	{
		return &leftXAxis;
	}

	int *getLeftYAxis()
	{
		return &leftYAxis;
	}

	int *getRightXAxis()
	{
		return &rightXAxis;
	}

	int *getRightYAxis()
	{
		return &rightYAxis;
	}

};

#endif
